package cn.learn.activiti.controller;

import cn.learn.activiti.domain.ActNodeConfig;
import cn.learn.activiti.service.ITaskService;
import cn.learn.activiti.util.RestResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author huangyezhan
 * @version 1.0
 * @date 2021年03月12日22:33
 */
@Slf4j
@RequiredArgsConstructor
@RequestMapping(path = "/activity/task")
@RestController
public class TaskController {
    private final ITaskService taskService;

    /**
     * 待处理任务
     */
    @GetMapping
    public RestResponse page(@RequestParam String name) {
        return RestResponse.success(taskService.waiting4Task(0, 10, name));
    }

    /**
     * 处理任务
     */
    @PutMapping("/taskId")
    public RestResponse completeTask(@RequestParam String taskId, @RequestParam String name) {
        ActNodeConfig config = new ActNodeConfig()
                .setMessage("测试用例")
                .setReceiver("测试人");
        return RestResponse.success(taskService.completeTask(taskId, name, config));
    }

    /**
     * 拾取任务
     */
    @PutMapping("/claim")
    public RestResponse claim(@RequestParam String taskId, @RequestParam String name) {
        return RestResponse.success(taskService.claim(taskId, name));
    }

    /**
     * 转派任务
     */
    @PutMapping("/assignmentAssignee")
    public RestResponse assignmentAssignee(@RequestParam String taskId, @RequestParam String userId) {
        taskService.assignmentAssignee(taskId, userId);
        return RestResponse.success();
    }

    /**
     * 任务回退
     */
    @PutMapping("/rollback")
    public RestResponse rollback(@RequestParam String taskId) {
        taskService.rollbackTask(taskId);
        return RestResponse.success();
    }


}
